<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('销假')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="col-sm-8">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-leaveapply-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">请假人：</label>
                <div class="col-sm-8">
                    <input name="userId" class="form-control" type="text" th:value="${apply.userId}" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">类型：</label>
                <div class="col-sm-8">
                    <input name="leaveType" class="form-control" type="text" th:value="${apply.leaveType}" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">起始时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="startTime" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text" th:value="${startTime}" readonly>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">结束时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="endTime" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text" th:value="${endTime}" readonly>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">原因：</label>
                <div class="col-sm-8">
                    <textarea type="text" name="reason" class="form-control" th:text="${apply.reason}" readonly></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">实际起始时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="realityStartTime" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">实际结束时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="realityEndTime" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-3 col-sm-offset-3">
                    <input type="hidden"  name="taskid" id="taskid" th:value="${taskid}">
                    <input type="hidden"  name="id" id="id" th:value="${apply.id}">
                    <button class="btn btn-primary" onclick="submitHandler()" type="button"><i class="fa fa-check"></i>&nbsp;提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="ibox-content" class="col-sm-4">
    <div id="vertical-timeline" class="vertical-container dark-timeline">
    </div>
</div>
</body>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "task/manage"
    $("#form-leaveapply-add").validate({
        focusCleanup: true
    });

    $("input[name='realityStartTime']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true
    });

    $("input[name='realityEndTime']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true
    });

    function submitHandler() {
        var taskid = $("#taskid").val();
        $.operate.save("update", $('#form-leaveapply-add').serialize(), function(){
            var json = {};
            $.ajax({
                url : prefix + "/completeTask/" + taskid,
                type : "POST",
                data : JSON.stringify(json), //转JSON字符串
                dataType: 'json',
                contentType:'application/json;charset=UTF-8', //contentType很重要
                success : function(result) {
                    $.modal.msg("办理成功");
                    const parent = window.parent;
                    // 我的待办
                    const myToDoIframe = parent.document.querySelector("iframe[src='/task/manage/mytask']");
                    // 我的全部待办
                    const myAllToDoIframe = parent.document.querySelector("iframe[src='/task/manage/alltasks']");
                    myToDoIframe && myToDoIframe.contentWindow.location.reload(true);
                    myAllToDoIframe && myAllToDoIframe.contentWindow.location.reload(true);
                    $.modal.closeTab();
                }
            });
        });
    }

    $(document).ready(function(){
        // 获取时间轴
        $.get(prefix + "/history/" + $("#taskid").val(), function(data){
            for (var a = 0; a < data.length ; a++) {
            $("#vertical-timeline").append("<div class=\"vertical-timeline-block\"><div class=\"vertical-timeline-icon lazur-bg\">" +
                "<i class=\"fa fa-briefcase\"></i></div>" +
                "<div class=\"vertical-timeline-content\">" +
                "<span class=\"vertical-date\">开始 <small>" + data[a].startTime + "</small></span><br>" +
                "<h2><b>" + data[a].assignee + ":</b>" + data[a].taskName + "</h2>" +
                "<p>" + (data[a].comment || "-") + "</p>" +
                "<span class=\"vertical-date\">结束 <small>" + (data[a].endTime || "-") + "</small></span>" +
                "</div>" +
                "</div>");
            }
        });
    });
</script>
</body>
</html>